﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class PlayerController : MonoBehaviour
{
	public float speed;
	public float rotationSpeed;
	public Text countText;
	public int count;
	public Canvas canvas;
	public Camera cameraz;

	void Start () 
	{
		count = 5;
		SetCountText ();
		canvas.enabled = false;
		SetFOV ();
	}

	void FixedUpdate () 
	{	
		float translation = Input.GetAxis("Vertical") * speed;
		float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
		translation *= Time.deltaTime;
		rotation *= Time.deltaTime;
		transform.Translate(0, 0, translation);
		transform.Rotate(0, rotation, 0);
	}

	void OnTriggerEnter(Collider other)
	{
		if (other.gameObject.tag == "PickUp") 
		{
			other.gameObject.SetActive(false);
			count = count - 1;
			SetCountText ();
		}
	}

	public int GetCount()
	{
		return count;
	}

	void SetCountText()
	{
		countText.text = "Count: " + count.ToString();
		if (count == 0) 
		{
			canvas.enabled = true;
		}
	}

	void SetFOV()
	{
		cameraz.fieldOfView = PlayerPrefs.GetInt("FOV");
	}
}	﻿